package com.sec.android.app.myfiles.facade.cmd;

import android.content.Context;

import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.fragment.optimizestorage.OptimizeStorageFileListFragment;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.search.SearchFragment;
import com.sec.android.app.myfiles.provider.PrivateMyFilesProvider;

import org.puremvc.java.multicore.interfaces.INotification;
import org.puremvc.java.multicore.patterns.command.SimpleCommand;

public class ReloadCmd extends SimpleCommand {

    public void execute(INotification notification) {
        Object[] params = (Object[]) notification.getBody();
        FileRecord record = (FileRecord) params[1];
        AbsMyFilesFragment curFragment = (AbsMyFilesFragment) params[2];

        if (record.getStorageType() == FileRecord.StorageType.Cloud || curFragment instanceof SearchFragment) {
            curFragment.reload();
        } else {
            if (record.getStorageType() == FileRecord.StorageType.OptimizeStorage) {
                ((OptimizeStorageFileListFragment) curFragment).reload(true);
            }
            Context context = (Context) params[0];
            Boolean isForced = (Boolean) params[3];
            PrivateMyFilesProvider.refreshDb(context, record, isForced);
        }
    }
}
